[][src]Crate usvg

usvg (micro SVG) is an SVG simplification tool.

Purpose

Imagine, that you have to extract some data from the SVG file, but your library/framework/language doesn't have a good SVG library. And all you need is paths data.

You can try to export it by yourself (how hard can it be, right). All you need is an XML library (I'll hope that your language has one). But soon you realize that paths data has a pretty complex format and a lot of edge-cases. And we didn't mention attributes propagation, transforms, visibility flags, attribute values validation, XML quirks, etc. It will take a lot of time and code to implement this stuff correctly.

So, instead of creating a library that can be used from any language (impossible), usvg takes a different approach. It converts an input SVG to an extremely simple representation, which is still a valid SVG. And now, all you need is to convert your SVG to a simplified one via usvg and an XML library with some small amount of code.

Key features of the simplified SVG

  • No basic shapes (rect, circle, etc). Only paths
  • Simple paths:
    • Only MoveTo, LineTo, CurveTo and ClosePath will be produced
    • All path segments are in absolute coordinates
    • No implicit segment commands
    • All values are separated by space
  • All (supported) attributes are resolved. No implicit one
  • No use. Everything is resolved
  • No invisible elements
  • No invalid elements (like rect with negative/zero size)
  • No units (mm, em, etc.)
  • No comments
  • No DTD
  • No CSS (partial support)
  • No script (simply ignoring it)

Full spec can be found here.

Limitations

  • Currently, it's not lossless. Some SVG features isn't supported yet and will be ignored.
  • CSS support is minimal.
  • Scripting and animation isn't supported and not planned.
  • a elements will be removed.
  • Unsupported elements:
    • some filter-based elements
    • font-based elements

Modules

prelude

Basic traits for tree manipulations.

utils

Some useful utilities.

Structs

AspectRatio

Representation of the preserveAspectRatio attribute.

BaseGradient

A generic gradient.

ClipPath

A clip-path element.

Color

Representation of the <color> type.

ConvolveMatrix

A convolve matrix representation.

EnableBackground

An enable-background.

FeBlend

A blend filter primitive.

FeColorMatrix

A color matrix filter primitive.

FeComponentTransfer

A component-wise remapping filter primitive.

FeComposite

A composite filter primitive.

FeConvolveMatrix

A matrix convolution filter primitive.

FeDiffuseLighting

A diffuse lighting filter primitive.

FeDisplacementMap

A displacement map filter primitive.

FeDistantLight

A distant light source.

FeFlood

A flood filter primitive.

FeGaussianBlur

A Gaussian blur filter primitive.

FeImage

An image filter primitive.

FeMerge

A merge filter primitive.

FeMorphology

A morphology filter primitive.

FeOffset

An offset filter primitive.

FePointLight

A point light source.

FeSpecularLighting

A specular lighting filter primitive.

FeSpotLight

A spot light source.

FeTile

A tile filter primitive.

FeTurbulence

A turbulence generation filter primitive.

Fill

A fill style.

Filter

A filter element.

FilterPrimitive

A filter primitive element.

FontSize

A font-size value.

Group

A group container.

Image

A raster image element.

LinearGradient

A linear gradient.

Mask

A mask element.

NonZeroF64

A non-zero f64.

NormalizedValue

A normalized value.

Options

Processing options.

Path

A path element.

PathData

An SVG path data container.

Pattern

A pattern element.

Point

A 2D point representation.

PositiveNumber

A positive number.

RadialGradient

A radial gradient.

Rect

A rect representation.

Size

A 2D size representation.

Stop

Gradient's stop element.

Stroke

A stroke style.

StrokeMiterlimit

A stroke-miterlimit value.

StrokeWidth

A stroke-width value.

SubPathData

A reference to a PathData subpath.

SubPathIter

An iterator over PathData subpaths.

Svg

An SVG root element.

Transform

Representation of the <transform> type.

TransformedPath

An iterator over transformed path segments.

Tree

A nodes tree container.

ViewBox

View box.

XmlOptions

An XML writing options.

Enums

Align

Representation of the align value of the preserveAspectRatio attribute.

ColorChannel

A color channel.

ColorInterpolation

A color interpolation mode.

Error

List of all errors.

FeBlendMode

An images blending mode.

FeColorMatrixKind

A color matrix filter primitive kind.

FeCompositeOperator

An images compositing operation.

FeEdgeMode

An edges processing mode.

FeImageKind

Kind of the feImage data.

FeLightSource

A light source kind.

FeMorphologyOperator

A morphology operation.

FeTurbulenceKind

A turbulence kind for the feTurbulence filter.

FillRule

A fill rule.

FilterInput

Identifies input for a filter primitive.

FilterKind

A filter kind.

ImageData

A raster image container.

ImageFormat

An image codec.

ImageRendering

An image rendering method.

LineCap

A line cap.

LineJoin

A line join.

NodeKind

Node's kind.

Paint

A paint style.

PathSegment

A path's absolute segment.

ShapeRendering

A shape rendering method.

SpreadMethod

A spread method.

TextRendering

A text rendering method.

TransferFunction

A transfer function used by FeComponentTransfer.

Units

An element units.

Visibility

A visibility property.

XmlIndent

An XML node indention.

Traits

FuzzyEq

A trait for fuzzy/approximate equality comparisons of float numbers.

FuzzyZero

A trait for fuzzy/approximate comparisons of float numbers.

IsDefault

Checks that type has a default value.

IsValidLength

Checks that the current number is > 0.

NodeExt

Additional Node methods.

TransformFromBBox

Converts Rect into bbox Transform.

Functions

load_svg_file

Loads SVG, SVGZ file content.

Type Definitions

Node

Alias for rctree::Node<NodeKind>.

Opacity

An alias to NormalizedValue.

SharedPathData

A reference-counted PathData.

StopOffset

An alias to NormalizedValue.